unit uStarLane;

{*
  Starlanes are fastest and safest way to travel between systesm.
*}

interface

uses cuVector;

type
  TStarLane = class( TObject )
    startPoint : integer;
    endPoint   : integer;

    procedure setStarLane(A,B:integer);
    procedure setStartPoint(theAstro:integer);
    procedure setEndPoint(theAstro:integer);
  end;

  tStarLaneList = class( TObject )
    Items : array of TStarLane;
    Count : integer;

    procedure createStarLanes();
    function findStarLane(theAstroID:integer):integer;
  end;

implementation

uses cuSorting, cuDebug, SysUtils;

//============== StarLane

procedure tStarLane.setStarLane(A,B:integer);
begin
  startPoint := A;
  endPoint   := B;
end;

procedure tStarLane.setStartPoint(theAstro:integer);
begin
  startPoint := theAstro;
end;
procedure tStarLane.setEndPoint(theAstro:integer);
begin
  endPoint := theAstro;
end;

//=============== StarLaneList

procedure TStarLaneList.createStarLanes();
var A,B,C:integer; RouteFound:boolean; SortList : TSortList;
begin
{  DevConsole.Print(LOG_DEBUG1, '[TUniverse] createStarLanes() '+IntToStr(uniStarList.Count));

  SortList := TSortList.Create();
//  SortList.Clear();
  SortList.setArray( uniStarList.Count );

  for A := 0 to uniStarList.Count-1 do
  begin
    DevConsole.Print(LOG_DEBUG3, '[TUniverse] Add Values to Sort Array');

    for B := 0 to uniStarList.Count-1 do
    begin
      SortList.setValueF(B, B, getAstro(uniStarList.Items[A]).astroLocation.getDistance2D( getAstro(uniStarList.Items[B]).astroLocation.X, getAstro(uniStarList.Items[B]).astroLocation.Y) );
    end;

    DevConsole.Print(LOG_DEBUG3, '[TUniverse] Sorting Floats()');
    SortList.ShellSortFloat();

    DevConsole.Print(LOG_DEBUG3, '[TUniverse] Select Closest Object');
    B := SortList.Items[1].Index; // 0 = Self, 1 = Closest Astro
    uniStarLane.Add( TStarlane.Create() );
    getStarLane( A ).setStarLane( uniStarList.Items[A], uniStarList.Items[B] );

    B := SortList.Items[2].Index; // 0 = Self, 1 = Closest Astro
    uniStarLane.Add( TStarlane.Create() );
    getStarLane( A ).setStarLane( uniStarList.Items[A], uniStarList.Items[B] );

    B := SortList.Items[3].Index; // 0 = Self, 1 = Closest Astro
    uniStarLane.Add( TStarlane.Create() );
    getStarLane( A ).setStarLane( uniStarList.Items[A], uniStarList.Items[B] );

    DevConsole.Print(LOG_DEBUG2, '[TUniverse] Creating starLane from '+IntToStr(getStarLane( A ).startPoint)+' -> '+IntToStr(getStarLane( A ).endPoint)+' : '+FormatFloat('0.00', SortList.Items[1].ValueF));
//    DevConsole.Print(LOG_DEBUG2, '[TUniverse] Creating starLane from '+IntToStr(A)+' -> '+IntToStr(B)+' : '+FormatFloat('0.00', SortList.Items[1].ValueF));
  end;

  FreeAndNil( SortList );
}
end;

function TStarLaneList.findStarLane(theAstroID:integer):integer;
begin
end;

end.
